<?php
/**
 * Class Order
 * Desc  订单Model
 * Create on 2021/8/18 15:40
 * Create by wangyafang
 */

namespace app\api\model\xyb;


use addons\xyb\XypHelper;

class OrderReward extends Base
{
    protected $name = 'xyb_order_reward';


    public static function createOrderReward($orders, $amount)
    {
        $forms = [
            'order_id' => $orders['id'],
            'order_no' => XypHelper::xyb_get_order_no(),
            'pay_order_no' => XypHelper::xyb_get_order_no(),
            'agent_id' => $orders['agent_id'],
            'user_id' => $orders['user_id'],
            'receive_id' => isset($orders['receive_id']) ? $orders['receive_id'] : 0,
            'type' => isset($orders['type']) ? $orders['type'] : 0,
            'status' => 0,
            'price' => $amount,
            'total_fee' => $amount,
            'pay' => 0,
            'createtime' => time(),
        ];
        $reward = OrderReward::create($forms);
        return $reward;
    }

    public static function checkOrderPayment($order_id){
        return OrderReward::where('id', $order_id)->where('pay', 1)->find();
    }

    public static function getOrderReward($order_id){
        $fields = 'id,order_id,order_no,pay_order_no,agent_id,user_id,receive_id,type,status,price,total_fee,pay';
        return OrderReward::field($fields)->where('order_id', $order_id)->where('pay', 1)->find();
    }

    public static function getOrderPaymentRewardLists($order_id){
        $fields = 'id,order_id,order_no,pay_order_no,agent_id,user_id,receive_id,type,status,price,total_fee,pay';
        return OrderReward::field($fields)->where('order_id', $order_id)->where('status', 1)->where('pay', 1)->select();
    }
    public static function getOrderRewardInfo($order_id){
        $fields = 'id,order_id,order_no,pay_order_no,agent_id,user_id,receive_id,type,status,price,total_fee,pay';
        return OrderReward::field($fields)->where('id', $order_id)->find();
    }
}